{% extends "resource/layout.html" %}
{% block title %}
    Home
{% endblock %}
{% block content %}
    <h2>
        Azure Resources
        <a href="{% url 'resource:resources' auth subscription|urlencode:'' 'location' %}">location</a>
        <a href="{% url 'resource:resources' auth subscription|urlencode:'' 'type' %}">type</a>
        <a href="{% url 'resource:resources' auth subscription|urlencode:'' 'subscription__name' %}">订阅</a>
        <a href="{% url 'resource:resources' auth subscription|urlencode:'' 'subscription__auth__display_name' %}">账号</a>
        <a href="{% url 'resource:resources' auth subscription|urlencode:'' 'resource_group' %}">资源组</a>
    </h2>
    
    {% if auth_list %}
    <select name="auth_list" onchange="window.location=this.value;">
        <option value="{% url 'resource:resources' 'auth' 'subscription' group_by %}"  {% if auth == 'auth' %}selected="selected"{% endif %}>全部</option>
        {% for auth_name in auth_list %}
            <option value="{% url 'resource:resources' auth_name.0 'subscription' group_by %}"  {% if auth == auth_name.0 %}selected="selected"{% endif %}>{{ auth_name.1 }}</option>
        {% endfor %}
    </select>
    {% endif %}

    {% if subscription_list %}
    <select name="subscription_list" onchange="window.location=this.value;">
        <option value="{% url 'resource:resources' auth 'subscription' group_by %}"  {% if subscription == 'subscription' %}selected="selected"{% endif %}>全部</option>
        {% for subscription_name in subscription_list %}
            <option value="{% url 'resource:resources' auth subscription_name|urlencode:'' group_by %}"  {% if subscription == subscription_name %}selected="selected"{% endif %}>{{ subscription_name }}</option>
        {% endfor %}
    </select>
    {% endif %}

    {% if resources %}
        <table class="resources">
            <thead>
            <tr>
                <th>{{ group_by }}</th>
                <th>count</th>
            </tr>
            </thead>
            <tbody>
            {% for res in resources %}
                <tr>
                    <td>{{ res.0 }}</td>
                    <td>{{ res.1 }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>No auth in the system.</p>
    {% endif %}
{% endblock %}